var say = function () { 
	var args = jQuery.makeArray(arguments);
	var msg = '>> ';
	if (args.length === 1) {
		msg += args.shift();
	} else {
		msg += args.join(', ');
	}
	console.log(msg);
};

var utils = (function($){
	var cookie = new Mojo.Model.Cookie('cookie');
	if (!cookie.get()) {
		say('initializing empty cookie');
		cookie.put({});
	}

	function disableActiveScene(cmdMenuModel, activeScene) {
		$.each(cmdMenuModel.items[0].items, function(i,item) {
			cmdMenuModel.items[0].items[i].disabled = false;
			if (item.command === activeScene) {
				cmdMenuModel.items[0].items[i].disabled = true;
			}
		});
		return cmdMenuModel;
	}

	return {
		addMenu: function(sceneController) {
			var c = sceneController;
			var cmdMenuModel = AppAssistant.cmdMenuModel;
			var cmdMenuAttrs = {};
			cmdMenuModel = disableActiveScene(cmdMenuModel,c.sceneName);
			c.setupWidget(Mojo.Menu.commandMenu, cmdMenuAttrs, cmdMenuModel);
		}, 
		dir: function(obj) {
			var members = [], v;
			for (v in obj) { members.push(v); }
			$.each(members.sort(), function(i,item) {
				v = $.isFunction(obj[item]) ? "function" : obj[item];
				say(item + ": " + v);
			});
		},
		get: function(key) {
			if (key) {

				return typeof cookie.get(key) === 'string' ? cookie.get(key) : undefined;
			} else {
				return cookie.get();
			}
		},
		set: function(k,v) {
			say(k + " => " + v);
			var obj = cookie.get();
			obj[k] = v;
			cookie.put(obj);
		},
		destroy: function() {
			cookie.put({});
		}
	};
})(jQuery);

